package com.glink.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.glink.common.util.BaseCommonUtils;

import java.io.IOException;
import java.util.Date;
import java.util.Objects;

/**
 * yyyy-MM-dd HH:mm:ss.SSS
 * Created by rencl on 2017/12/27.
 */
public class JsonDateSerializerOfMilliSecond extends JsonSerializer<Date> {
    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
            throws IOException {
        if (Objects.nonNull(date)) {
            String value = BaseCommonUtils.DATE_FORMAT_MILLISECOND_1.format(date);
            gen.writeString(value);
        } else {
            gen.writeString("");
        }
    }
}
